﻿using System.Collections.Generic;
using System.Linq;

namespace KataPotter.Logic
{
    public class BuildSeries
    {
        public static List<int> GetSeriesCountFromSelectedBooks(int[] SelectedBooks)
        {
            if (SelectedBooks.Length == 0){return new List<int>();}

            var Series = new List<int>();

            while (SelectedBooks.Sum() > 0)
            {
                var CountOfBooksInSeries = 0;
                for (int Position = 0; Position < SelectedBooks.Length; Position++)
                {
                    if (SelectedBooks[Position] != 0)
                    {
                        CountOfBooksInSeries++;
                        SelectedBooks[Position]--;
                    }
                }
                Series.Add(CountOfBooksInSeries);
            }


            return Series;
        }
    }
}